package servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import dao.Info;
import dao.InfoImpl;

/**
 * Servlet implementation class UpdateInfo
 */
@WebServlet(
		name="UpdateInfo",
		urlPatterns= {"/servlet/UpdateInfo"},
		loadOnStartup = 1
		
		)
public class UpdateInfo extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public UpdateInfo() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		//response.getWriter().append("Served at: ").append(request.getContextPath());
		doPost(request,response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		//doGet(request, response);
		response.setContentType("text/html,charset=utf-8");
		request.setCharacterEncoding("utf-8");
		String id =request.getParameter("id");
		String name =request.getParameter("name");
		String sex=request.getParameter("sex");
		String birthday=request.getParameter("birthday");
		String icard =request.getParameter("icard");
		String section=request.getParameter("section");
		String job=request.getParameter("job");
		String jdate=request.getParameter("jdate");
		String wdate=request.getParameter("wdate");
		String nationality=request.getParameter("nationality");
		String place=request.getParameter("place");
		String phone=request.getParameter("phone");
		String email=request.getParameter("email");
		String heigth=request.getParameter("heigth");
		String bplace=request.getParameter("bplace");
		String registeredop=request.getParameter("registeredop");
		String school=request.getParameter("school");
		String major=request.getParameter("major");
		Info info=new Info();
		info.setId(id);
		info.setName(name);
		info.setSex(sex);
		info.setBirthday(birthday);
		info.setIcard(icard);
		info.setSection(section);
		info.setJob(job);
		info.setJdate(jdate);
		info.setWdate(wdate);
		info.setNationality(nationality);
		info.setPlace(place);
		info.setPhone(phone);
		info.setEmail(email);
		info.setHeigth(heigth);
		info.setBplace(bplace);
		info.setRegisteredop(registeredop);
		info.setSchool(school);
		info.setMajor(major);
		InfoImpl infobean=new InfoImpl();
		int n=infobean.update(info);
		if(n>0) {
			request.getRequestDispatcher("/info.jsp").forward(request, response);
		}else {
			request.getRequestDispatcher("/error.jsp").forward(request, response);
		}
	}

}
